﻿@{
    ViewBag.Title = "RoleUserList";
    Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
@section head {
    @if (false)
    {<script src="~/Scripts/jquery-1.6.4-vsdoc.js" type="text/javascript"></script>}
    <link href="@Url.Content("~/Content/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.ztree.all-3.0.min.js")" type="text/javascript"></script>
    @Html.Partial("_JqGrid")
    <script language="javascript" type="text/javascript">
        var selectId = "";
        var gridId = "#tableId";
        $(document).ready(function () {
            //更新皮肤
            funGridInit();
        });
        function Save(t, prepage) {
            var data = new Array();
            var rowIds = $(gridId).jqGrid('getGridParam', 'selarrrow');
            if (rowIds == "") {
                alert("请选择用户!");
                return;
            };
            if (rowIds != null && rowIds != undefined) {
                var array = rowIds.toString().split(',');
                var UserIds = '';
                for (var i = 0; i < array.length; i++) {
                    UserIds += $(gridId).getCell(array[i], 'User_ID') + ",";
                }
                if (UserIds.length > 0)
                    UserIds = UserIds.substring(0, UserIds.length - 1);

                $.post('@Url.Content("~/SystemManage/Role/SaveRoleUsers")', { roleId: '@ViewBag.RoleId', userIds: UserIds }, function (data) {
                    debugger;
                    if (data.ErrorMessage == '' || data.ErrorMessage == null) {
                        parent.asyncbox.tips('保存成功!', 'success');
                        //                        MainFrame().$(MainFrame().gridId).trigger("reloadGrid");
                        prepage.$(prepage.gridId).trigger("reloadGrid");
                        parent.$.close(t.id);
                    }
                    else {
                        alert("操作失败!失败原因：" + data.ErrorMessage);
                    }
                });
            }
            return true;
        }

        function Search() {
            //查询
            $(gridId).setGridParam({ page: 1 });
            $(gridId).trigger("reloadGrid");
        }
        function funGridInit() {
            //初始化表格
            var option = {
                height: $("#divGridContainer").height() - 51,
                width: $("#divGridContainer").width() - 2,
                url: '@Url.Content("~/SystemManage/Role/GetUserList/")' + '@ViewBag.RoleId',
                autowidth: false,
                datatype: "json",
                sortname: 'User_ID',
                multiselect: true,
                sortorder: 'asc',
                colModel: [
                { label: '用户编号', name: 'User_Code', width: 100 },
                { label: '用户名称', name: 'User_Name', width: 100 },
                { label: '所在部门', name: 'Organization_Name', width: 200 },
                { hidden: true, name: 'User_ID' }
   	            ],
                onSelectRow: function (rowid, cellname, value, iRow, iCol) {
                    selectId = $(gridId).getCell(rowid, "User_ID");
                },
                ondblClickRow: function (rowid) {

                },
                beforeRequest: function (d) {
                    // $(gridId).jqGrid('setGridParam', { postData: data });
                }
            };
            var o = jqGridHelper.getConfig("#pageId", option);
            $(gridId).jqGrid(o);
        }
    </script>
    <!--主窗体，页面都需要的div-->
<div id="divGridContainer" class="ui-layout-center" style="overflow: auto;">
    <table id="tableId">
    </table>
    <div id="pageId">
    </div>
</div>
